<template>
  <a-drawer
    width="576"
    :title="formTitle"
    :label-col="4"
    :wrapper-col="14"
    :visible="open"
    :body-style="{height:'calc(100vh - 100px)',overflow:'auto'}"
    @close="cancel">
    <a-form-model ref="form" :model="form" :rules="rules" layout="vertical">
      <a-spin :spinning="spinning" :delay="delayTime" tip="Loading...">
        <a-row :gutter="32">
          <a-col :span="12" >
            <a-form-model-item label="供应商编号" prop="supplierId">
              <a-select
                placeholder="请选择供应商编号"
                v-model="form.supplierId"
                :getPopupContainer="
                  triggerNode => {
                    return triggerNode.parentNode || document.body
                  }
                "
                style="width: 100%"
                allow-clear>
                <a-select-option v-for="(d, index) in supplierList" :key="index" :value="d.id">{{ d.name }}</a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="运费" prop="shipPrice">
              <a-input-number v-model="form.shipPrice" :min="0" style="width: 100%"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="优惠价格" prop="discountPrice">
              <a-input-number v-model="form.discountPrice" :min="0" style="width: 100%"/>
            </a-form-model-item>
          </a-col>
          <a-col :span='24'>
            <a-form-model-item label='采购条目' prop='billItems'>
              <a-table :data-source="form.billItems" :columns="columns" :rowKey="(r,i)=>{ return i}" :pagination='false'>
                <template slot="materialId" slot-scope="text, record">
                  <a-select placeholder="请选择原材料" v-model="record.materialId" allow-clear>
                    <a-select-option v-for="(d, index) in materialList" :key="index" :value="d.id">{{ d.name }}</a-select-option>
                  </a-select>
                </template>
                <template slot="price" slot-scope="text, record">
                  <a-input-number v-model="record.price" :min="0" />
                </template>
                <template slot="count" slot-scope="text, record">
                  <a-input-number v-model="record.count" :min="0" />
                </template>
                <template slot="action" slot-scope="text, record">
                  <a-icon type='delete' @click='removeItem(record)'/>
                </template>
              </a-table>
            </a-form-model-item>
          </a-col>
          <a-col :span='24'>
            <a-form-item>
              <a-button type='dashed' block @click='addItem'>
                <a-icon type='plus' />
                增加条目
              </a-button>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="备注" prop="remark">
              <a-textarea v-model="form.remark" placeholder="请输入备注" :rows="4"/>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-spin>
      <div class="bottom-control">
        <a-space>
          <a-button :disabled="disabled" @click="cancel">
            取消
          </a-button>
          <a-button type="primary" :disabled="disabled" @click="submitForm(true)">
            保存
          </a-button>
        </a-space>
      </div>
    </a-form-model>
  </a-drawer>
</template>
<script>
import TinaBillEditForm from './TinaBillForm'
export default {
  ...TinaBillEditForm
}
</script>
